import React    from 'react';

import Base     from './BaseComponent';

export default class extends Base {

    state = {list: []};

    page = {index: 1, size: 10};

    _end = false;
    _method = _.noop;
    _getList = () => 'list';
    _setTitle = _.noop;

    componentWillMount(){
        this._setTitle();
        this.load();
    }

    reset(){
        this._end = false;
        this.page.index = 1;
    }

    load(){
        this.props[this._method()](this.page).then(list => {
            this.setState({[this._getList()]: list});
        });
    }

    reload(){
        if(!this._end){
            this.page.index++;
            return this.props[this._method()](this.page).then(list => {
                this._end = list.length === 0;
                this.setState({[this._getList()]: this.state[this._getList()].concat(list)});
            });
        }
    }

}
